<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>登录</title>
	<script src="lib/ionic/js/angular/angular.js"></script>
</head>
<body background="img/bg-login.jpg" ng-app="login" ng-controller="LoginCtrl">
	<div>
		<p align="center">欢迎使用SRH维修人员版</p>
	</div>
	<div style="width:100%;height:40vh;">
		
	</div>
	<div style="text-align:center;">
		<input type="text" placeholder="请输入手机号：" ng-model="phoneNumber">
		<p></p>
		<input type="password" placeholder="请输入密码：" ng-model="password">	
		<p></p>
		<input type="button" value="工作人员登录" ng-click="login(phoneNumber,password)">
	</div>
	<script>
	//登录界面 ---这是一个独立的用户登录的界面 用户第一次登录时会进入这个界面
		var app = angular.module('login',[]);


			app.factory('$$ls',function($window){
			  return {
			    set : function(key,value){
			      $window.localStorage[key] = value;

			    },
			    get : function(key,defaultValue){
			      return $window.localStorage[key]||defaultValue;
			    },
			    setObject : function(key,value){
			      $window.localStorage[key] = JSON.stringify(value);
			    },
			    getObject : function(key){
			      return JSON.parse($window.localStorage[key] || '{}');
			    }
			  }
			})

		app.controller('LoginCtrl',function($scope,$http,$$ls){
	
			$scope.login = function(phoneNumber,password){
			
				$http({
			      method:'POST',
			      url:"http://123.56.220.33:3000/users/login",//工作端请求数据
			      data:{account:phoneNumber,"password":password,type:2},
			      timeout:2000
			    })
			    .success(function(data){
			    	$$ls.set('phoneNumber',phoneNumber);
			    	$$ls.set('group',"1");
			    	$$ls.set('groupName',"木工"); 

			    	window.location.href="home.html"; 

			    })
			    .error(function(data,status,headers,config){ 
			      
			    });
			}

		})
	</script>
</body>
</html>
